home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Ahoy 1987 August
/
Ahoy_Magazine_87-08_1987_Double_L_Side_A.d64
/
Short Sort 1
(
.txt
)
< prev
next >
Wrap
Commodore BASIC
|
2022-10-26
|
1KB
|
25 lines
0 print"[147]":poke53280,12:poke53281,12:poke646,0
1 rem ==================================
2 rem commodares problem #40-2 :
3 rem short sort
4 rem ==================================
10 for i=1 to 6 : a(i)=int(rnd(0)*1000)-500:print a(i);:qq(i)=a(i):next i:print
20 for jj=1 to 5 : on jj gosub 110,210,310,410,510
30 for i=1 to 6 : a(i)=qq(i) : next i : print : next jj
99 end
100 rem * solution by jim speers ***********************************************
110 fori=1to6:k=1:forj=1to6:k=k-(a(j)>a(k))*(j-k):next:printa(k);:a(k)=-9e9:next
120 return
200 rem * solution by stephane edwardson****************************************
210 fory=1to5:forz=yto6:a=a(y):b=a(z):a(y)=-a*(a<=b)-b*(b<a):a(z)=a+b-a(y):nextz,y:forn=1to6:printa(n);:next
220 return
300 rem * solution by ron gow *************************************************
310 forx=1to6:b=0:fory=1to6:b=b-(a(y)<=a(x)):next:c(b)=a(x):next:forn=1to6:printc(n);:next
320 return
400 rem * solution by d.bruce powell ******************************************
410 fori=1to5:forj=i+1to6:t=a(j):d=t-a(i):k=d<0:a(j)=t+k*d:a(i)=t-(1+k)*d:nextj:printa(i);:nexti:printa(i);
420 return
500 rem * solution by jeff achtnig **************** c-128 only ***************
510 fory=1to6:f=999999999:a(z)=f:forx=1to6:iff>a(x)thenf=a(x):z=x:nextx:printf;:nexty:(NULL)nextx:printf;:nexty
520 return